﻿@using CubicFWNet.Data.Models
@using CubicFWNet.Data.ViewModal
@model Order
@{
    //var product = ViewBag.Product as Product;
    var invoice = ViewBag.Invoice as Invoice;
    var sc = ViewBag.SendCar as SendCar;
    var exp = ViewBag.ExpressOrder as ExpressOrder;
    var customerShortName = ViewBag.CustomerShortName;
    var invoceTypeName = ViewBag.InvoceTypeName;
    var proList = ViewBag.DeliveryProductList as IEnumerable<DeliveryProduct>;
}
<section class="content-header">
    <h1>
        运输审核
    </h1>
    <ol class="breadcrumb">
        <li><a href="javascript:void(0);"><i class="fa fa-dashboard"></i>@Resources.Global.PageTitle</a></li>
        <li><a href="@Url.Action("Index", "Home")">首页</a></li>
        <li class="active"><a href="@Url.Action("TransportExamine", "Transport")">运输审核</a></li>
    </ol>
</section>
<section class="content">
    <div class="box box-solid">
        <!-- /.box-header -->
        <div class="box-body">
            <div class="row">
                @if (Model != null && invoice != null)
                {
                    <form class="form-horizontal" id="frmedit" action="@Url.Action("UpdateInvoiceExamineType", "Transport")" method="post">
                        <input type="hidden" id="OrderId" name="OrderId" value="@Model.Id" />
                        <input type="hidden" id="Id" name="Id" value="@invoice.Id" />
                        <div class="box-body">
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">发货单号</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="Number" name="Number" value="@invoice.Number" readonly="readonly">
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">订单号</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="OrderNumber" name="OrderNumber" value="@Model.Number" readonly="readonly">
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">收货单位</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="TakeCompany" name="TakeCompany" value="@invoice.TakeCompany" readonly="readonly">
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">简称</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="customerShortName" name="customerShortName" value="@customerShortName" readonly="readonly">
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">填单日期</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="operationTime" name="operationTime" placeholder="" value="@invoice.CreateTime" readonly="readonly">
                                </div>
                            </div>

                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">发货日期</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="DliveryTime" name="DliveryTime" value="@invoice.DliveryTime" readonly="readonly">
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">预计到货日期</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="ReceivedTime" name="ReceivedTime" value="@invoice.ReceivedTime" readonly="readonly">
                                </div>
                            </div>
                            <div class="form-group col-md-6" style="display: none">
                                <label class="col-sm-3 control-label">收货人</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="ReceivePeople" name="ReceivePeople" value="@invoice.ReceivePeople" readonly="readonly">
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">发货人</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="SendPeople" name="SendPeople" value="@invoice.SendPeople" readonly="readonly">
                                </div>
                            </div>
                            @*<div class="form-group col-md-6">
                                    <label class="col-sm-3 control-label">承运商</label>
                                    <div class="col-sm-9">
                                        <input type="text" class="form-control" id="Carrier" name="Carrier" value="@invoice.Carrier" readonly="readonly">
                                    </div>
                                </div>
                                <div class="form-group col-md-6">
                                    <label class="col-sm-3 control-label">发货仓库</label>
                                    <div class="col-sm-9">
                                        <input type="text" class="form-control" id="StoreName" name="StoreName" value="@invoice.StoreName" readonly="readonly">
                                        <select class="form-control" id="StoreType" name="StoreType">
                                                <option value="1">商品仓</option>
                                                <option value="2">原料仓</option>
                                            </select>
                                                            </div>
                                                        </div>*@
                            <div class="form-group col-md-12" style="height: 1px;"></div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">送货要求</label>
                                <div class="col-sm-9">
                                    <textarea class="form-control" rows="3" placeholder="请输入 ..." name="DliveryDemand" id="DliveryDemand" readonly="readonly">@invoice.DliveryDemand</textarea>
                                </div>
                            </div>
                            <div class="form-group col-md-12" style="height: 1px;"></div>

                            <div id="json-content" class="col-md-12 ">
                                @*col-md-offset-1*@
                                @*<div class="form-group col-md-6">
                                        <label class="col-sm-3 control-label">数量</label>
                                        <div class="col-sm-9">
                                            <input type="text" class="form-control okeydown" data-des="数量" id="Amount" name="Amount" value="@tmView.Amount">
                                        </div>
                                    </div>*@
                                <input type="hidden" id="modalData" value="@invoice.Data" readonly="readonly">
                                <table class="footable table table-stripped table-bordered table-hover" id="footable">
                                    <thead>
                                        <tr>
                                            <th data-sort-ignore="true">
                                                品名
                                            </th>
                                            <th data-hide="phone,table" data-sort-ignore="true">
                                                尺寸宽-mm
                                            </th>
                                            <th data-hide="phone,table" data-sort-ignore="true">
                                                尺寸长-mm
                                            </th>
                                            <th data-hide="phone,table" data-sort-ignore="true">
                                                基本单位
                                            </th>
                                            <th data-hide="phone,table" data-sort-ignore="true" class="col-md-2">
                                                数量
                                            </th>
                                            <th data-hide="phone,table" data-sort-ignore="true" class="col-md-2">
                                                价格
                                            </th>
                                            <th data-hide="phone,table" data-sort-ignore="true" class="col-md-1">
                                                增值税
                                            </th>
                                            <th data-hide="phone" data-sort-ignore="true" class="col-md-2">
                                                金额
                                            </th>
                                        </tr>
                                    </thead>
                                    <tbody id="data-content">
                                        @if (proList != null)
                                        {
                                            foreach (var item in proList)
                                            {
                                                var totalMoney = item.ProductPrice * item.ProductAmount * item.ProductTax;
                                                <tr class="tr">
                                                    <td>
                                                        @Html.DisplayFor(modelItem => item.ProductName)
                                                        <input type="hidden" class="form-control" data-des="产品Id" id="ProductId" name="ProductId" value="@item.ProductId">
                                                        <input type="hidden" class="form-control" data-des="品名" id="ProductName" name="ProductName" value="@item.ProductName">
                                                    </td>
                                                    <td>
                                                        @Html.DisplayFor(modelItem => item.ProductSizeWidth)
                                                        <input type="hidden" class="form-control" data-des="尺寸宽-mm" id="ProductSizeWidth" name="ProductSizeWidth" value="@item.ProductSizeWidth">
                                                    </td>
                                                    <td>
                                                        @Html.DisplayFor(modelItem => item.ProductSizeLenth)
                                                        <input type="hidden" class="form-control" data-des="尺寸长-mm" id="ProductSizeLenth" name="ProductSizeLenth" value="@item.ProductSizeLenth">
                                                    </td>
                                                    <td>
                                                        @Html.DisplayFor(modelItem => item.ProductUnit)
                                                        <input type="hidden" class="form-control" data-des="基本单位" id="ProductUnit" name="ProductUnit" value="@item.ProductUnit">
                                                    </td>
                                                    <td>
                                                        <input type="text" class="form-control okeydown itemAmount" data-des="数量" data-itemprice="@item.ProductPrice" id="ProductAmount" name="ProductAmount" value="@item.ProductAmount" required>
                                                        @*@Html.DisplayFor(modelItem => item.Amount)*@
                                                    </td>
                                                    <td>
                                                        <input type="text" class="form-control okeydown itemPrice" data-des="价格" id="ProductPrice" name="ProductPrice" value="@item.ProductPrice" readonly="readonly">
                                                        @*@Html.DisplayFor(modelItem => item.Price)*@
                                                    </td>
                                                    <td>
                                                        <input type="text" class="form-control productTaxClass" data-des="增值税" id="ProductTax" name="ProductTax" value="@item.ProductTax" readonly="readonly">
                                                    </td>
                                                    <td>
                                                        <input type="text" class="form-control okeydown itemMoney" data-des="金额" id="TotalMoney" name="TotalMoney" value="@totalMoney.ToString("f2")" readonly="readonly">
                                                    </td>
                                                </tr>
                                            }
                                        }
                                    </tbody>
                                </table>
                            </div>
                            <div class="form-group col-md-12" style="height: 1px;"></div>
                            @if (!string.IsNullOrEmpty(invoceTypeName))
                            {
                                <div class="form-group col-md-6">
                                    <label for="operationName" class="col-sm-3 control-label">发货方式</label>
                                    <div class="col-sm-9">
                                        <input type="text" class="form-control" value="@invoceTypeName" readonly="readonly">
                                    </div>
                                </div>
                            }
                            <div class="form-group col-md-12" style="height: 1px;"></div>
                            @if (invoice.Type == 1 && sc != null)
                            {
                                <div id="car">
                                    <div class="form-group col-md-6">
                                        <label for="operationName" class="col-sm-3 control-label">客户名称</label>
                                        <div class="col-sm-9">
                                            <input type="text" class="form-control" value="@customerShortName" readonly="readonly">
                                        </div>
                                    </div>
                                    @*<div class="form-group col-md-6">
                                            <label for="operationName" class="col-sm-3 control-label">付费方式</label>
                                            <div class="col-sm-9">
                                                <input type="text" class="form-control" id="PayType" name="PayType" value="@sc.PayType" readonly="readonly" />
                                            </div>
                                        </div>
                                        <div class="form-group col-md-6">
                                            <label for="operationName" class="col-sm-3 control-label">发货单编号</label>
                                            <div class="col-sm-9">
                                                <input type="text" class="form-control" id="Number" name="Number" value="@sc.Number" readonly="readonly" />
                                            </div>
                                        </div>*@
                                    <div class="form-group col-md-6">
                                        <label for="operationName" class="col-sm-3 control-label">货物总值</label>
                                        <div class="col-sm-9">
                                            <input type="text" class="form-control" id="Worth" name="Worth" value="@sc.Worth" readonly="readonly" />
                                        </div>
                                    </div>
                                    <div class="form-group col-md-6">
                                        <label class="col-sm-3 control-label">送货要求</label>
                                        <div class="col-sm-9">
                                            <textarea class="form-control" rows="3" placeholder="请输入 ..." name="Demand" id="Demand" readonly="readonly">@sc.Demand</textarea>
                                        </div>
                                    </div>
                                </div>
                            }
                            @if (invoice.Type == 2 && exp != null)
                            {
                                <div id="express">
                                    <div class="form-group col-md-6">
                                        <label for="operationName" class="col-sm-3 control-label">客户名称</label>
                                        <div class="col-sm-9">
                                            <input type="text" class="form-control" value="@customerShortName" readonly="readonly">
                                        </div>
                                    </div>
                                    <div class="form-group col-md-6">
                                        <label for="operationName" class="col-sm-3 control-label">快递名称</label>
                                        <div class="col-sm-9">
                                            <input type="text" class="form-control" id="ExpTypeName" name="ExpTypeName" value="@exp.ExpTypeName" readonly="readonly" />
                                        </div>
                                    </div>
                                    <div class="form-group col-md-6">
                                        <label for="operationName" class="col-sm-3 control-label">快递编号</label>
                                        <div class="col-sm-9">
                                            <input type="text" class="form-control" id="ExpNumber" name="ExpNumber" value="@exp.ExpNumber" readonly="readonly" />
                                        </div>
                                    </div>
                                </div>
                            }
                            <div class="form-group col-md-12" style="height: 1px;"></div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">备注</label>
                                <div class="col-sm-9">
                                    <textarea class="form-control" rows="3" readonly="readonly">@invoice.Memo</textarea>
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">审核备注</label>
                                <div class="col-sm-9">
                                    <textarea class="form-control" rows="3" placeholder="请输入 ..." name="ExamineMemo" id="ExamineMemo"></textarea>
                                </div>
                            </div>
                            <div class="form-group col-md-12" style="height: 1px;"></div>
                            <div class="form-group col-md-6">
                                <label for="operationName" class="col-sm-3 control-label">操作人</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="operationName" name="operationName" value="@invoice.CreatorName" readonly="readonly">
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label for="operationTime" class="col-sm-3 control-label">日期</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="operationTime" name="operationTime" value="@invoice.CreateTime" readonly="readonly">
                                </div>
                            </div>
                        </div>
                        <div class="box-footer" style="width: 80%; margin-left: 20px;">
                            <a role="button" href="javascript:void(0)" class="btn btn-primary submitbtn" onclick="formsubmit(1)">确认</a>
                            <a class="btn btn-primary submitbtn" href="@Url.Action("TransportExamine", "Transport")">返回</a>
                        </div>
                    </form>
                }
            </div>
        </div>
    </div>
</section>

<div id="loadingPage" style="display: none;">
    <div class="loading-shade"></div>
    <div class="loading-content" onclick="$.loading(false)">数据加载中，请稍后…</div>
</div>

@section Scripts{
    <script type="text/javascript">
        $(document).ready(function () {
            $("#frmedit").validate({
                submitHandler: function (form) {
                    var postData = $(form).formSerialize();
                    postData.Data = getParam(); //JSON.stringify(postData._Data);
                    $.submitForm({
                        url: $(form).attr("action"),
                        param: postData,
                        success: function () {
                            //$.reload();
                            $.modalAlert("操作成功", "success");
                            window.location.href = '@Url.Action("TransportExamine", "Transport")';
                        }
                    });
                }
            });
            //$('#footable').footable();
        });

        var type = 1;

        function formsubmit(t) {
            type = t;
            $("#frmedit").submit();
        }

        function getParam() {
            var postdata = [];
            //主键
            $("#json-content").find('.tr').each(function (r, i) { //input,select,textarea
                var postdataItem = {};
                $(i).find('input').each(function (m) {
                    var $this = $(this);
                    var id = $this.attr('id');
                    postdataItem[id] = $this.val();
                });
                postdata.push(postdataItem);
            });
            return JSON.stringify(postdata);
        }

        $(".itemAmount").keyup(function () {
            var amount = $(this).val() / 1;
            var price = $(this).attr('data-itemprice');
            var tax = $(this).parents(".tr").find(".productTaxClass").val();
            if (isNaN(tax)) {
                tax = 1.17;
            }
            tax = tax / 1;
            var b = (amount * price * tax).toFixed(2);

            $(this).parents(".tr").find(".itemMoney").val(b);
        });

        $(".okeydown").on("keydown", function () {
            var k = event.keyCode;
            if ((k <= 57 && k >= 48) || (k <= 105 && k >= 96) || (k == 8) || (k == 110) || (k == 190)) {
                return true;
            } else {
                return false;
            }
        });
    </script>
}